package com.tengju.bff.interfaces.covercharge.util;

import lombok.extern.slf4j.Slf4j;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Slf4j
public class regularUtils {
    /**
     * 判断是不是数字
     * @param string
     * @return true为包含，false为不包含
     */
    public static boolean isNum(String string){
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(string);
        if( !isNum.matches() ){//不满足
            return false;
        }else{//满足
            return true;
        }
    }

    /**
     * 判断有没有包含特殊字符
     * @param string
     * @return bool
     */
    public static boolean specialCharacters(String string){
        String regEx = "[ _`~!@#$%^&*+=|{}':;',\\[\\].<>/?~！@#￥%……&*——+|{}【】‘；：”“’。，、？]|\n|\r|\t";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(string);
        if( m.find()){//包含
            return false;
        }else{//不包含
            return true;
        }
    }

    /**
     * 只支持大小写字母，数字
     * @param string
     * @return bool
     * */
    public static boolean numTheLetter(String string){
        String regex = "^[a-z0-9A-Z]+$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(string);
        if( m.find()){//包含
            return true;
        }else{//不包含
            return false;
        }
    }
}
